/*
 * trdp_mini_private.h
 *
 *  Created on: 2016年12月26日
 *      Author: think
 */

#ifndef INC_TRDP_MINI_PRIVATE_H_
#define INC_TRDP_MINI_PRIVATE_H_

#include "../api/trdp_mini.h"

#ifdef __cplusplus
extern "C" {
#endif



/** Various flags for PD and MD Block control block   */
typedef enum
{
    FLAGS_DEFAULT 	 = 0,        				/**< Default value defined in tlc_openDession will be taken     */
    FLAGS_ENABLE   	 = 0x01,     				/**< enable or disable: 0-> disable 1-> enable                  */
	FLAGS_MODE		 = 0x02,					/**< this block is for send data or receive data  0: request as source, 1: receive as suit  */
	FLAGS_AUTO		 = 0x04						/**< for source port, 1: auto loop to send data, 0: send data only once   */
} FLAGS_BITS_T;


/* Free block header array, one entry for each possible free block size */
typedef struct
{
	/**< memory block define for 16 bytes block    	*/
#if TRDP_MINI_BLKCNT_16B > 0
	struct m16B_T{
		INT32U	isValid;						//if the block has been used 0: not used,  1: used
		INT8U	data[16];
	}mb16B[TRDP_MINI_BLKCNT_16B];
#endif
	/**< memory block define for 32 bytes block    	*/
#if TRDP_MINI_BLKCNT_32B > 0
	struct m32B_T{
		INT32U	isValid;						//if the block has been used 0: not used,  1: used
		INT8U	data[32];
	}mb32B[TRDP_MINI_BLKCNT_32B];
#endif
	/**< memory block define for 64 bytes block    	*/
#if TRDP_MINI_BLKCNT_64B > 0
	struct m64B_T{
		INT32U	isValid;						//if the block has been used 0: not used,  1: used
		INT8U	data[64];
	}mb64B[TRDP_MINI_BLKCNT_64B];
#endif
	/**< memory block define for 128 bytes block    */
#if TRDP_MINI_BLKCNT_128B > 0
	struct m128B_T{
		INT32U	isValid;						//if the block has been used 0: not used,  1: used
		INT8U	data[128];
	}mb128B[TRDP_MINI_BLKCNT_128B];
#endif
	/**< memory block define for 256 bytes block    */
#if TRDP_MINI_BLKCNT_256B > 0
	struct m256B_T{
		INT32U	isValid;						//if the block has been used 0: not used,  1: used
		INT8U	data[256];
	}mb256B[TRDP_MINI_BLKCNT_256B];
#endif
	/**< memory block define for 512 bytes block    */
#if TRDP_MINI_BLKCNT_512B > 0
	struct m512B_T{
		INT32U	isValid;						//if the block has been used 0: not used,  1: used
		INT8U	data[512];
	}mb512B[TRDP_MINI_BLKCNT_512B];
#endif
	/**< memory block define for 1024 bytes block   */
#if TRDP_MINI_BLKCNT_1024B > 0
	struct m1024B_T{
		INT32U	isValid;						//if the block has been used 0: not used,  1: used
		INT8U	data[1024];
	}mb1024B[TRDP_MINI_BLKCNT_1024B];
#endif
	/**< memory block define for 1348 bytes block   */
#if TRDP_MINI_BLKCNT_1348B > 0
	struct m1348B_T{
		INT32U	isValid;						//if the block has been used 0: not used,  1: used
		INT8U	data[1348];
	}mb1348B[TRDP_MINI_BLKCNT_1348B];
#endif
}MEM_CTRL_T;

/** Queue element for PD packets to send or receive    */
typedef struct
{
	INT32U					flagBits;			/*control block's flag bits										*/
	COM_TYPE_T				comType;			/*trdp communication type										*/
	INT8U					srcIpAddr[4];		/**< source IP address for filtering          					*/
	INT8U					destIpAddr[4];		/**< destination IP address for filtering     					*/
	INT16U     				msgType;        	/**< Protocol ('PD', 'MD', ...)                                 */
	INT32U          		seqCount;       	/**< sequence counter                                           */
	INT32U          		comId;          	/**< ComID                                                      */
	INT32U          		etbTopoCnt;     	/**< received ETB topocount                                     */
	INT32U          		replyComId;     	/**< ComID for reply (request only)                             */
	INT8U  					replyIpAddr[4];    	/**< IP address for reply (request only)                        */
	const void 				*pMemory;			/* point to memory block 										*/
	INT32U					blockSize;			/* data holder's size											*/
	INT32U					dataSize;			/* valid data size												*/
	TRDP_MINI_PD_CALLBACK_T	pUserCbFunc;		/* user's call back function									*/
	INT32U					interval;			/* auto send data's interval									*/
	INT32U					lastTimerCnt;		/* last time's timer's count									*/
	TRDP_MINI_ERR_T			resultCode;			/**< error code													*/
} PD_INFO_T;

/** Queue element for MD packets to send or receive    */
typedef struct
{
	INT32U					flagBits;			/*control block's flag bits						*/
	INT8U      				srcIpAddr[4];          /**< source IP address for filtering         */
	INT8U      				destIpAddr[4];         /**< destination IP address for filtering    */
    INT32U              	seqCount;           /**< sequence counter                           */
    INT16U              	protVersion;        /**< Protocol version                           */
    INT16U          		msgType;            /**< Protocol ('PD', 'MD', ...)                 */
    INT32U              	comId;              /**< ComID                                      */
    INT32U              	etbTopoCnt;         /**< received topocount                         */
    BOOLEAN             	aboutToDie;         /**< session is about to die                    */
    INT32U              	userStatus;         /**< error code, user stat                      */
    INT8U         			sessionId[16];      /**< for response                               */
    INT32U              	replyTimeout;       /**< reply timeout in ms given with the request */
    INT8S     				destURI[32];        /**< destination URI user part from MD header   */
    INT8S     				srcURI[32];         /**< source URI user part from MD header        */
    const void 				*pMemory;			/* point to memory block 						*/
	INT32U					blockSize;			/* data holder's size							*/
	INT32U					dataSize;			/* valid data size								*/
    TRDP_MINI_MD_CALLBACK_T	pUserCbFunc;		/* user's call back function					*/
    INT32U					interval;			/* auto send data's interval					*/
    INT32U					lastTimerCnt;		/* last time's timer's count					*/
    TRDP_MINI_ERR_T         resultCode;         /**< error code                                 */
} MD_INFO_T;



#ifdef __cplusplus
}
#endif

#endif /* INC_TRDP_MINI_PRIVATE_H_ */
